<template>
  <div>
    <el-form-item label="值类型">
      <el-switch active-text="数组" inactive-text="字符串" v-model="localData.cascaderProps.emitPath" />
    </el-form-item>
    <el-form-item label="支持多选">
      <el-switch v-model="localData.cascaderProps.multiple" />
    </el-form-item>
    <el-form-item label="支持搜索">
      <el-switch v-model="localData.filterable" />
    </el-form-item>
    <el-form-item label="支持清空">
      <el-switch v-model="localData.clearable" />
    </el-form-item>
    <el-form-item label="父子不关联">
      <el-switch v-model="localData.cascaderProps.checkStrictly" />
    </el-form-item>
    <el-form-item label="显示完整路径">
      <el-switch v-model="localData.showAllLevels" />
    </el-form-item>
    <el-form-item label="路径分割符">
      <el-input v-model="localData.separator" placeholder="请输入路径分割符" />
    </el-form-item>
    <el-form-item label="展开方式">
      <el-radio-group v-model="localData.cascaderProps.expandTrigger">
        <el-radio-button label="点击" value="click" />
        <el-radio-button label="悬浮" value="hover" />
      </el-radio-group>
    </el-form-item>
    <el-form-item label="选择器尺寸">
      <el-radio-group v-model="localData.size">
        <el-radio-button label="默认" value="default" />
        <el-radio-button label="大" value="large" />
        <el-radio-button label="小" value="small" />
      </el-radio-group>
    </el-form-item>
    <el-form-item label="节点配置">
      <div>标题字段: <el-input v-model="localData.cascaderProps.label" /></div>
      <div>值字段: <el-input v-model="localData.cascaderProps.value" /></div>
      <div>子节点字段: <el-input v-model="localData.cascaderProps.children" /></div>
      <div>禁用字段: <el-input v-model="localData.cascaderProps.disabled" /></div>
    </el-form-item>
    <el-form-item label="文本绑定属性">
      <el-cascader
        :props="CascaderProps"
        :options="attrList"
        v-model="localData.bindLabel"
        placeholder="请选择属性"
        filterable
        clearable
        :show-all-levels="false"
      >
        <template #default="{ data: opt }">
          <span>{{ `${opt.entityDesc}(${opt.entityName})` }}</span>
        </template>
      </el-cascader>
    </el-form-item>
    <el-form-item label="数据配置">
      <span style="margin-right: 8px">{{ getDictType }}</span>
      <text-edit-button text="配置" @click="openDictEdit" />
    </el-form-item>

    <cascader-data-setting v-model="visible" :data="localData" :options="formJson" @submit="handleDictUpdate" />
  </div>
</template>
    
    <script>
import cascaderDataSetting from './cascaderDataSetting.vue';
export default {
  name: 'AnvilCascaderConfig',
  components: { cascaderDataSetting },
  props: {
    data: {
      type: Object,
      default: () => {}
    },
    formJson: {
      type: Object,
      default: () => {}
    },
    attrList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      localData: {},
      visible: false,
      CascaderProps: {
        value: 'entityName',
        label: 'entityDescName',
        children: 'childList',
        emitPath: false
      },
    };
  },
  computed: {
    getDictType() {
      switch (this.localData.dicOption) {
        case 'static':
          return '静态数据';
        case 'remote':
          return '接口获取';
        default:
          return '静态数据';
      }
    }
  },
  watch: {
    data: {
      handler(newVal) {
        this.localData = newVal;
      },
      deep: true,
      immediate: true
    },
    localData: {
      handler(newVal) {
        this.$emit('update:data', newVal);
      },
      deep: true
    }
  },
  created() {},
  methods: {
    openDictEdit() {
      this.visible = true;
    },
    handleDictUpdate(data) {
      for (let key in data) {
        this.localData[key] = data[key];
      }
    }
  }
};
</script>    